<?php
class Admin_HinhThucThiController extends Zend_Controller_Action
{
	public function init()
	{
	
	}
	public function indexAction()
	{
		$hinhthucthiMapper = Data_Model_HinhThucThiMapper::getInstance();
		$hinhthucthi = $hinhthucthiMapper->hinhthucthiList();
		$this->view->hinhthucthi = $hinhthucthi;
	}
	public function themAction()
	{
		$this->view->title = "Thêm Hình Thức Thi";
		$formThem = new Admin_Form_HinhThucThiForm();
		$formThem->setMethod('post');
		$formThem->setAction('/QLHV/public/admin/hinhthucthi/them/');
		$formThem->addElement('submit','submit',array('label'=>'Thêm'));
		$this->view->form = $formThem;
		if($this->getRequest()->isPost())
		{
			if($formThem->isValid($_POST))
			{
				$data = $formThem->getValues();
				
				$hinhthucthi = $data['hinhthucthi'];
				
				$hinhthucthiMapper = Data_Model_HinhThucThiMapper::getInstance();
				
				$hinhthucthiObj = new Data_Model_HinhThucThi();
				$hinhthucthiObj->setHinhthucthi($hinhthucthi);
				
				$hinhthuc = $hinhthucthiMapper->save($hinhthucthiObj);
				$this->_redirect('/admin/hinhthucthi/index/');
			}
		}
	}
	public function capnhatAction()
	{
		$this->view->title = "Cập Nhật Hình Thức Thi";
		$formCapnhat = new Admin_Form_HinhThucThiForm();
		$formCapnhat->setMethod('post');
		$formCapnhat->setAction('/QLHV/public/admin/hinhthucthi/capnhat/');
		$formCapnhat->addElement('hidden','MaHinhThuc');
		$formCapnhat->addElement('submit','submit',array('label'=>'Cập nhật'));
		$this->view->form = $formCapnhat;
		$hinhthuc_id = $this->getRequest()->getParam('id');
		$hinhthucthiMapper = Data_Model_HinhThucThiMapper::getInstance();
		if($this->getRequest()->isPost())
		{
			if($formCapnhat->isValid($_POST))
			{
				$data = $formCapnhat->getValues();
	
				$maht = $data['MaHinhThuc'];
				$hinhthucthi = $data['hinhthucthi'];
	
				
	
				$hinhthucthiObj = new Data_Model_HinhThucThi();
				$hinhthucthiObj->setId($maht);
				$hinhthucthiObj->setHinhthucthi($hinhthucthi);
	
				$hinhthuc = $hinhthucthiMapper->save($hinhthucthiObj);
				$this->_redirect('/admin/hinhthucthi/index/');
			}
		}
		else 
		{
			$htt = $hinhthucthiMapper->searchHinhThucById($hinhthuc_id);
			
			$formCapnhat->getElement('MaHinhThuc')->setValue($htt->getId());
			$formCapnhat->getElement('hinhthucthi')->setValue($htt->getHinhthucthi());
		}
	}
	public function xoaAction()
	{
		$this->_helper->viewRenderer->setNoRender(true);
		$maht = $this->getRequest()->getParam('id');
		$hinhthucthiMapper = Data_Model_HinhThucThiMapper::getInstance();
		$hinhthucthiMapper->delete($maht);
		$this->_redirect('/admin/hinhthucthi/index');
	}
}